package com.opensource.excel.core;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.collection.CollUtil;

public class XTable {

	private String     Id;
	private Class<?>   clazz;
	private List<XRow> rows;

	public String getId() {
		return Id;
	}

	public void setId(String id) {
		Id = id;
	}

	public Class<?> getClazz() {
		return clazz;
	}

	public void setClazz(Class<?> clazz) {
		this.clazz = clazz;
	}

	public List<XRow> getRows() {
		return rows;
	}

	public void setRows(List<XRow> rows) {
		this.rows = rows;
	}

	public void addRow(XRow xRow) {
		if (null == rows) {
			rows = new ArrayList<>();
		}
		rows.add(xRow);
	}

	/**
	 * 获取表头的行数
	 * @return
	 */
	public int getRowSize() {
		if (CollUtil.isEmpty(rows)) {
			return 0;
		} else {
			return rows.size();
		}
	}

	/**
	 * 配置的表头所处的第几行索引位获取批对的规则。 即第几行出现了批对规则
	 * @return
	 */
	public int getHeaderIndex() {
		for (int i = 0; i < getRowSize(); i++) {
			XRow xRow = rows.get(i);
			if (xRow.isValidRow()) {
				return i ;
			}
		}
		return -1;
	}

}
